<?php
namespace app\xiangmu\controller;
class Orderxiangmu extends Base {
    //列表
    public function lists() {
        if (is_post()) {
            $d = $this->post;
            $map = [];
            if($d['keyword']){ $map[] = ['and','b.username|c.title','like',"%{$d['keyword']}%"]; }
            if($d['pay_status']){ $map[] = ['and','a.pay_status','=',$d['pay_status']]; }
            if($d['xiangmu_id']){ $map[] = ['and','a.xiangmu_id','=',$d['xiangmu_id']]; }
            if($d['min_time']) $map[] = ['and','a.create_time','>=',strtotime($d['min_time'])];
            if($d['max_time']) $map[] = ['and','a.create_time','<=',strtotime($d['max_time'])];
            $w = where($map);
            $rs = $this->db->query("select a.*,b.username,c.title from order_xiangmu a left join user b on a.user_id=b.id left join xiangmu c on a.xiangmu_id=c.id $w[0] order by a.id desc" . limit($d['page'], $d['limit']), $w[1], '', true);
            if ($rs) {
                foreach ($rs[0] as $key => $val) {
                  $rs[0][$key]['pay_status'] = c("type.pay_status")[$val['pay_status']];
                  $rs[0][$key]['create_time'] = date('Y-m-d H:i', $val['create_time']);
                }
                suc($rs[0], $rs[1]);
            } else {
                suc([], 0);
            }
        }
        $xiangmu = $this->db->query("select id,title from xiangmu where status=0 order by sort desc,id desc");
        $this->fetch(['xiangmu' => $xiangmu],'','layadmin');
    }
}
